package com.gl.util;

public class ServerUtil {

    public static String IP = "81.70.235.33";
    //测试
    public static String TestIP = "127.0.0.1";
    public static int PORT = 7101;
    public static String SERVER_PORT = "8083";

    // 将中文字符串转换为Unicode编码
    public static String chineseToUnicode(String str) {
        StringBuilder unicodeStr = new StringBuilder();

        for (char c : str.toCharArray()) {
            unicodeStr.append("\\u").append(Integer.toHexString(c));
        }

        return unicodeStr.toString();
    }

    // 将Unicode编码转换为中文字符串
    public static String unicodeToChinese(String unicodeStr) {
        StringBuilder chineseStr = new StringBuilder();

        String[] unicodeArr = unicodeStr.split("\\\\u");
        for (int i = 1; i < unicodeArr.length; i++) {
            int code = Integer.parseInt(unicodeArr[i], 16);
            chineseStr.append((char) code);
        }

        return chineseStr.toString();
    }

    public static void main(String[] args) {
        // 中文字符串
        String chineseStr = "你好，世界！";

        // 将中文转换为Unicode编码
        String unicodeStr = chineseToUnicode(chineseStr);
        //system.out.println("Unicode编码: " + unicodeStr);

        // 将Unicode编码转换为中文
        String chineseStrConverted = unicodeToChinese(unicodeStr);
        //system.out.println("转换后的中文字符串: " + chineseStrConverted);
    }


}
